package cn.itcast.itcaststore.web.servlet.client;

import cn.itcast.itcaststore.serive.OrderService;
import cn.itcast.itcaststore.serive.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @Auther: 万秋泊
 * @Date: 2021/11/3 14:28
 * @Description: 支付，改变订单状态
 */
@WebServlet("/orderstate")
public class OrderStateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1.将要提交的数据得到
        // 获得订单号
        String orderid = request.getParameter("orderid");
        OrderService service = new OrderServiceImpl();
        try {
            service.updateOrderState(orderid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //支付成功，跳转到orderSuccess.jsp
        response.sendRedirect(request.getContextPath()+"/client/paysuccess.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
